package pro.softzhang.algo.lc800;

public class LC852_PeakIndexInAMountainArray {
    public static void main(String[] args) {
        int[] arr = new int[]{0,1,0};
        int idx = new Solution().peakIndexInMountainArray(arr);
        System.out.println(idx);
    }

    static class Solution {
        public int peakIndexInMountainArray(int[] arr) {
            int left = 1, right = arr.length - 2;
            while (left < right) {
                int middle = (left + right) / 2;
                if(arr[middle - 1] < arr[middle] && arr[middle] > arr[middle + 1]) {
                    return middle;
                }

                if(arr[middle] > arr[middle + 1]) {
                    right = middle - 1;
                } else {
                    left = middle + 1;
                }
            }

            return left;
        }
    }
}